package com.huatai.data.convert;

import com.google.common.collect.Lists;
import com.huatai.common.utils.ListUtils;
import com.huatai.data.jdbc.JdbcObject;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class JdbcConvert {

    public static List<JdbcObject> convert(List<Object> objects, List<Class<?>> clazzs) {
        if (ListUtils.isEmpty(objects))
            return null;
        List<JdbcObject> jdbcs = Lists.newArrayList();
        for (int i = 0; i < objects.size(); i++) {
            Object o = objects.get(i);
            JdbcObject jdbc = new JdbcObject();
            if (o == null) {
                jdbc.setClazz(clazzs.get(i));
            } else if (o instanceof String) {
                String str = ((String) o).trim();
                if (StringUtils.isNotBlank(str)) {
                    jdbc.setObject(str);
                } else {
                    jdbc.setClazz(String.class);
                }
            } else {
                jdbc.setObject(o);
            }
            jdbcs.add(jdbc);
        }
        return jdbcs;
    }

}
